
#装饰器函数
def foo(fun):
    def warp():
        print("start")
        fun()
        print("end")
        print (fun.__name__)
    return warp
def bar():
    print("I am in bar()")
f= foo(bar)
f()

print('-'*50)

def foo(fun):
    def warp():
        print("start")
        fun()
        print("end")
        print (fun.__name__)
    return warp
@foo   #语法糖
def bar():
    print("I am in bar()")
bar()

print('-'*50)

#lambda表达式

def add(x):
    x+=3
    return x
numbers = range(10)
list(numbers)
new_numbers = []
for i in numbers:
    new_numbers.append(add(i))

print(new_numbers)

new_numbers = [i+3 for i in numbers]
print(new_numbers)

lam = lambda x:x+3
n2 = []
for i in numbers:
    n2.append(lam(i))
print(n2)
print('-'*50)
g = lambda x,y:x**y
n=4
result=[g(n,i) for i in range(n)]
print(result)
print('-'*50)

#map表达式
numbers=[0,1,2,3,4,5,6,7,8,9]
result=list(map(lambda x:x+3,numbers))
print(result)

